import logging

import yaml

from yuekao.Page.Page import Page
from yuekao.Page.Page1 import Page1
from yuekao.Page.Page2 import Page2
from yuekao.Page.Page01 import Page

import time
from selenium import webdriver
import pytest

def read_yaml():
    with open('yaml.yaml','r',encoding='utf-8') as p:
        return yaml.safe_load(p)
#测试用例类
class Test_case():
    @pytest.fixture(scope='function')
    def driver(self):
        driver=webdriver.Edge()
        # driver.maximize_window()
        yield driver
        # 隐式等待
        driver.implicitly_wait(10)
        driver.quit()
    #登录
    @pytest.mark.parametrize('data',read_yaml())
    def test_login(self,driver,data):
        po=Page(driver)
        po.baidu_luoji_login(data)
    # 登录
    def test_login_01(self,driver):
        # 异常处理
        try:
            po=Page(driver)
            po.baidu_luoji_login()
        except Exception as e:
            str =time.strftime("%Y%m%d%H%M%S", time.localtime())
            driver.save_screenshot(str+'.png')
            print(e)

    # 搜索北京时间到第三页查看
    def test_baidu_02(self,driver):
        logging.info('start case')
        po=Page1(driver)
        po.baidu_luoji2()
        logging.info('end case')

    # 点击新闻选择新闻滚动到底部
    def test_baidu_03(self,driver):
        po=Page2(driver)
        po.baidu_luoji_02()



if __name__ == '__main__':
    pytest.main()
